function [graphPrices, graphYMat ] = plotAggCostIso(ctrS)

logEMin = min(ctrS.estim.bids.logE)-2;
logEMax = log(1e6);
numEVals = 501;
logEmissions = linspace(logEMin, logEMax, numEVals)';

numPriceVals = 501;
priceMin = 1;
priceMax = 50;
logPrices = linspace(log(priceMin), log(priceMax), numPriceVals)';

ctrS.estim.bids.index = (1:height(ctrS.estim.bids))';
one_row_per_pp_full = removevars(groupfilter(ctrS.estim.bids, "id_pp", @(x) x == min(x), "index"), "logE");
one_row_per_pp = one_row_per_pp_full(:, "id_pp");

graphTable = table();
for i = 1:height(one_row_per_pp)
    % Duplicate the current row
    duplicatedRow = repmat(one_row_per_pp(i, :), numEVals, 1);

    duplicatedRow.logE = logEmissions;

    % Append the duplicated row to the new table
    graphTable = [graphTable; duplicatedRow];
end

if ctrS.scenario.iso_type == "no_hetero"
    model_num=3;
elseif ctrS.scenario.iso_type == "hetero"
    model_num=4;
end

graphTable = outerjoin(graphTable,one_row_per_pp_full, 'Keys', "id_pp", 'MergeKeys',true);

graphTable.logPrice =predict(ctrS.estim.fits{model_num}, graphTable);

graphTableNew = graphTable(graphTable.id_period==ctrS.period,["id_pp", "logE", "logPrice"]);

spare_price_table = table();
one_row_per_pp = one_row_per_pp_full(:, ["id_pp", "id_plant", "id_period"]);
for i = 1:height(one_row_per_pp)
    % Duplicate the current row
    duplicatedRow = repmat(one_row_per_pp(i, :), numPriceVals, 1);

    duplicatedRow.logPrice = logPrices;

    % Append the duplicated row to the new table
    spare_price_table = [spare_price_table; duplicatedRow];
end
spare_price_table = spare_price_table(spare_price_table.id_period==ctrS.period,["id_pp", "logPrice"]);

graphTableMerged = outerjoin(graphTableNew,spare_price_table, ...
    'Keys',{'id_pp', 'logPrice'},'MergeKeys',true);

graphTableUnstack = unstack(graphTableMerged,"logE","id_pp") ;
graphTableUnstack = sortrows(graphTableUnstack, "logPrice", 'ascend');

temp = removevars(graphTableUnstack,"logPrice");
% Specify the columns that contain missing values
columnsToInterpolate = temp.Properties.VariableNames;

% Iterate over the columns to interpolate
for i = 1:numel(columnsToInterpolate)
    column = columnsToInterpolate{i};
    test = fillmissing(graphTableUnstack.(column), 'linear', 'SamplePoints', graphTableUnstack.logPrice);
    graphTableUnstack.(column) = test;
end

graphTableGraphSubset = graphTableUnstack(ismember(graphTableUnstack.logPrice,logPrices),:);
% Go from logs to linear
graphTableGraphSubset.price = exp(graphTableGraphSubset.logPrice);
graphTableUnstackY = removevars(graphTableGraphSubset, ["logPrice", "price"]);

graphYMat = exp(table2array(graphTableUnstackY));
graphPrices = graphTableGraphSubset.price;

end